<?php
// +----------------------------------------------------------------------
// | 上游文件服务
// +----------------------------------------------------------------------
// | 主要服务于文件和文件夹服务数据处理
// +----------------------------------------------------------------------
// | 错误编码头 249xxx
// +----------------------------------------------------------------------

namespace common\service;

use common\model\ModuleModel;
use common\model\VersionModel;
use support\SingletonTrait;

class UpstreamFileFolderDirectoryService
{
    use SingletonTrait;
    private $versionModel;
    private $moduleModel;

    public function __construct()
    {
        $this->versionModel = model(VersionModel::class);
        $this->moduleModel = model(ModuleModel::class);
    }




    /**
     * 获取上游发布文件信息
     * @param $param
     *
     * @return array|mixed|string
     */
    public function getUpstreamPublishFileByTaskId($param)
    {
        if(empty($param)){
            return [];
        }

        $moduleInfo = $this->moduleModel->where(['code' => 'task'])->column('id');
        $moduleId = array_pop($moduleInfo);

        $field = "id,project_id,link_id,json_unquote(json_extract(json, concat('$.','version_file_publish'))) as version_file_publish";

        $versionDataInfo = $this->versionModel
            ->where(['link_id' => $param['task_id'],'module_id' => $moduleId])
            ->field($field)
            ->select();

        if(empty($versionDataInfo)){
            return [];
        }

        return $versionDataInfo;

    }

}
